package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDem2 {
    public static void main(String[] args)throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        System.out.println("链接");
        Statement statement = connection.createStatement();
        /*
          向userinfo表插入一条数据
          INSERT INTO userinfo(username,password,nickname,age)
          VALUES('张三','123456','阿三','22')
         */
        String sql = "INSERT INTO userinfo(username,password,nickname,age)"+
        "VALUES('张三','123456','阿三','22')";
        /*
        int executeUpdate(String sql)
        用来执行SQL语句的方法(INSERT,UPDATE,DELETE)
        返回值为一个整数表示执行SQL后影响了表中多少条记录
         */
        int num = statement.executeUpdate(sql);
        if (num>0){
            System.out.println("插入成功");
        }else{
            System.out.println("插入失败");
        }
        connection.close();
    }
}
